package com.sheepshead.models;

import com.sheepshead.enums.CardEnum;
import com.sheepshead.enums.SuitEnum;

public class Card implements Comparable<Card>{
	
	private static int ACE_POINTS = 11;
	private static int KING_POINTS = 4;
	private static int QUEEN_POINTS = 3;
	private static int JACK_POINTS = 2;
	private static int TEN_POINTS = 10;
	private static int FAIL_POINTS = 0;
	
	private CardEnum value;
	private SuitEnum suit;
	private String cardName;
	private int pointValue;
	private boolean trump;
	private int belongsTo;

	public int getBelongsTo() {
		return belongsTo;
	}

	public void setBelongsTo(int belongsTo) {
		this.belongsTo = belongsTo;
	}

	public Card(CardEnum card, SuitEnum suit)
	{
		this.cardName = card.toString() + " of " + suit.toString();
		this.value = card;
		this.suit = suit;
		if((value.equals(CardEnum.QUEEN) || value.equals(CardEnum.JACK)) || suit.equals(SuitEnum.DIAMONDS))
		{
			trump = true;
		}
		else
		{
			trump = false;
		}
		switch (card)
		{
			case ACE: this.setPointValue(ACE_POINTS); break;
			case KING: this.setPointValue(KING_POINTS); break;
			case QUEEN: this.setPointValue(QUEEN_POINTS); break;
			case JACK: this.setPointValue(JACK_POINTS); break;
			case TEN: this.setPointValue(TEN_POINTS); break;
			default: this.setPointValue(FAIL_POINTS); break;
		}
	}
	
	public Card() {
	}

	public boolean isTrump() {
		return trump;
	}

	public void setTrump(boolean trump) {
		this.trump = trump;
	}

	public CardEnum getValue() {
		return value;
	}

	public void setValue(CardEnum value) {
		this.value = value;
	}

	public SuitEnum getSuit() {
		return suit;
	}

	public void setSuit(SuitEnum suit) {
		this.suit = suit;
	}

	public int getPointValue() {
		return pointValue;
	}

	public void setPointValue(int pointValue) {
		this.pointValue = pointValue;
	}

	public String getCardName() {
		return cardName;
	}

	public void setCardName(String cardName) {
		this.cardName = cardName;
	}

	public int compareTo(Card card) {
		if(card.isTrump() && !this.isTrump())
		{
			return 1;
		}
		if(this.isTrump() && !card.isTrump())
		{
			return -1;
		}
		if((card.getSuit() == this.getSuit()) && !this.trump)
		{
			return this.getValue().compareTo(card.getValue());
		}
		if(card.isTrump() && this.isTrump())
		{
			if(this.getValue().compareTo(card.getValue()) != 0)
			{
				return this.getValue().compareTo(card.getValue());
			}
			else
			{
				return this.getSuit().compareTo(card.getSuit());
			}
		}
		return 0;
	}
	
}
